package com.gjy.util.basic;

import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-06-04 15:42:36
 */
public class DateTimeUtil {

    public static String getLastDayOfMonth(String date) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        LocalDate localDate = LocalDate.parse(date, formatter);
        return localDate.withDayOfMonth(localDate.lengthOfMonth()).format(formatter);
    }

    public static String getFirstDayOfMonth(String date) {
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyyMM");
        YearMonth ym = YearMonth.parse(date, dtf);
        LocalDate lastDay = ym.atEndOfMonth();
        return lastDay.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
    }

}
